<!-- 新增/修改弹框 -->
<template>
  <!-- 新增/修改弹窗 -->
  <el-dialog
    v-model="dialogPreview.visible"
    :width="1200"
    :title="dialogPreview.title"
    draggable
    close-icon="CloseBold"
    :close-delay="200"
    style="margin-top: 5vh"
    @close="closeDialog"
  >
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <el-descriptions title="班组信息" :column="2">
          <el-descriptions-item label="班组名称">{{ dataInfo.name }}</el-descriptions-item>
          <el-descriptions-item label="管理部班组">{{
            dataInfo.isManagerGroup ? "是" : "否"
          }}</el-descriptions-item>
          <el-descriptions-item label="参建单位名称">{{ dataInfo.corpName }}</el-descriptions-item>
          <el-descriptions-item label="进场日期">{{ dataInfo.startDate }}</el-descriptions-item>
          <el-descriptions-item label="离场日期">{{ dataInfo.endDate }}</el-descriptions-item>
        </el-descriptions>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col>
        <el-table v-loading="loading" :data="tableList" highlight-current-row border>
          <el-table-column label="工人姓名" min-width="90" align="center" prop="personName" />
          <el-table-column label="证件号码" min-width="120" align="center" prop="cardNumber" />
          <el-table-column
            label="是否为班组长"
            min-width="120"
            align="center"
            prop="isLeader"
            :formatter="(row: any) => (row.isLeader? '是' : '否')"
          />
          <el-table-column
            label="是否签订劳动合同"
            min-width="120"
            align="center"
            prop="hasContract"
            :formatter="(row: any) => (row.hasContract? '是' : '否')"
          />
          <el-table-column label="工种" min-width="120" align="center" prop="typeName" />
          <el-table-column label="联系电话" min-width="90" align="center" prop="mobile" />
          <el-table-column label="进场日期" min-width="90" align="center" prop="startDate" />
          <el-table-column label="离场日期" min-width="90" align="center" prop="endDate" />
        </el-table>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script lang="ts" setup>
import { GetProjectGroupMemberByGroupId } from "@/api/worker/index";
import { ElMessage } from "element-plus";

//声明变量
const props = defineProps({
  dialogPreview: {
    type: Object,
    default: () => ({
      visible: false,
      title: "新增",
      footBtn: "确认新增",
      id: 0,
    }),
  },
  dataInfo: {
    type: Object,
    default: () => ({
      projectName: "",
    }),
  },
});

const { dialogPreview, dataInfo } = toRefs(props);
const emit = defineEmits(["sendClose"]);
const loading = ref(false);
const tableList = ref<any[]>([]);

watch(
  () => dialogPreview.value.visible,
  () => {
    if (dialogPreview.value.visible) {
      handleQuery();
    }
  }
);
/**
 * 关闭弹窗
 */
function closeDialog(needRefresh: boolean, workerInfo?: any) {
  emit("sendClose", needRefresh, workerInfo);
  tableList.value = [];
}

/* 列表查询 */
async function handleQuery() {
  loading.value = true;
  let list = await GetProjectGroupMemberByGroupId(dialogPreview.value.id);
  if (list.type === 0) {
    if (list.success) {
      tableList.value = list.data;
    } else {
      ElMessage.error(list.msg);
    }
  } else {
    ElMessage.error(list.msg);
  }
  loading.value = false;
}
</script>

<style lang="scss" scoped>
:deep(.el-upload__tip) {
  display: inline-block;
  margin-left: 10px;
}
</style>
